/*
 *  txdnet.cn tonydon
 * 
 */
package cn.txdnet.txcms.dao;

import cn.txdnet.txcms.domain.HotWord;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.mapper.HotWordMapper;
import cn.txdnet.txcms.query.HotWordQuery;
import cn.txdnet.txcms.query.ViewHotWordQuery;
import cn.txdnet.txweb.utils.CollectionUtil;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 *
 * @author txdnet
 */
public class HotWordDAO extends MybatisBaseDAO{
    
    /**
     * 插入 hotword
     * @param hotWord
     * @return 
     */
    public int insert(HotWord hotWord){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.insert(hotWord);
    }
    
    /**
     * 批量删除hotword
     * @param ida
     * @return 
     */
    public int delete(long[] ida){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.delete(ida);
    }
    
    /**
     * 批量更新发布时间
     * @param m
     * @return 
     */
    public int updatePubTime(Map m){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.updatePubTime(m);
    }
    
    /**
     * 批量更新停止时间
     * @param m
     * @return 
     */
    public int updateStopTime(Map m){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.updateStopTime(m);
    }
    
    /**
     * 批量更新类目
     * @param m
     * @return 
     */
    public int updateCatalog(Map m){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.updateCatalog(m);
    }
    
    /**
     * 更新排序号
     * @param m
     * @return 
     */
    public int updateOrderNum(Map m){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.updateOrderNum(m);
    }
    
    /**
     * 更新hotword
     * @param hotWord
     * @return 
     */
    public int updateHotWord(HotWord hotWord){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.updateHotWord(hotWord);
    }
    
    /**
     * 查询当前最大排序号
     * @return 
     */
    public long queryMaxOrderNum(){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.queryMaxOrderNum();
    }
    
    /**
     * 查询hotword用于编辑
     * @param id
     * @return 
     */
    public HotWord queryHotWordForEdit(Long id){
         HotWordMapper mapper = this.getMapper(HotWordMapper.class);
         return mapper.queryHotWordForEdit(id);
    }
    
    /**
     * 分页条件查询
     * @param query
     * @return 
     */
    public PageDTO queryByFactor(HotWordQuery query){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        query.filter();
        List list = mapper.listByFactor(query);
        if (query.getRownum().intValue() == 0 && CollectionUtil.isNotEmpty(list)) {
            query.setRownum(mapper.countByFactor(query));
        }
        return new PageDTO(list, query.getRownum());
    }
    
    // view
    
    /**
     * 前端查询类目下hotword list
     * @param query
     * @return 
     */
    public List<?> queryListForView(ViewHotWordQuery query){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        List<?> list = mapper.queryListForView(query);
        if(CollectionUtil.isEmpty(list)){
            return Collections.emptyList();
        }
        return list;
    }
    
    /**
     * 前端点击数更新
     * @param query
     * @return 
     */
    public int increaseHitNum(ViewHotWordQuery query){
        HotWordMapper mapper = this.getMapper(HotWordMapper.class);
        return mapper.increaseHitNum(query);
    }
    
}